import globalconst from "../../../../../../canvas/common/globalConst";
var global = globalconst.GlobalConst;
import utilfuncs from "../../../../../../canvas/common/tools/utilfuncs";
var funcs = utilfuncs.UtilFuncs;


//符号“$”隔开多个环，第一个环为外环；
//符号“@”隔开环内的子图元
//各子图元根据不同的类型有不同的描述方式
//"line,x1,y1;x2,y2;....@arc,cntx,cnty,radius,stangle,endangle,anticlockwise@bezier,st,ctrlPt1,
//ctrlPt2,end@quadratic,st,end,ctrlPt$line,x1,y1;x2,y2;....@arc,cntx,cnty,radius,stangle,endangle,anticlockwise" 

var SvgPath2LGXPathSvc = {}

SvgPath2LGXPathSvc.convert = function (unitInfoLst) {
    let stUnit = unitInfoLst[0];
    let outParam = { coordDesc: '' };
    this.getPathUnitDesc(stUnit, outParam, 0, unitInfoLst);
    let totalCoordDesc = outParam.coordDesc;
    return totalCoordDesc;
}


SvgPath2LGXPathSvc.getPathUnitDesc = function (pathUnit, outParam, idx, unitInfoLst) {
    let subDesc = "";
    if (!pathUnit){
        return ;
    }
    let mainType = funcs.mainObjType(pathUnit.type);
    if (mainType == global.BaseUnitPolyline) {
        subDesc = "@line,"
        subDesc = subDesc + pathUnit.pos.toString();
    }
    else if (mainType == global.BaseUnitArc) {
        subDesc = "@arc,";
        subDesc = subDesc + pathUnit.pos.toString();
    }
    else if (mainType == global.BezierCurve) {
        subDesc = "@bezier,";
        subDesc = subDesc + pathUnit.pos.toString();
    }
    else if (mainType == global.SpLine) {
        subDesc = "@spline,";
        subDesc = subDesc + pathUnit.pos.toString();
    }
    else if (mainType == global.BaseUnitEllipseArc) {
        subDesc = "@ellipseArc,";
        subDesc = subDesc + pathUnit.pos.toString();
    }
    outParam.coordDesc = outParam.coordDesc + subDesc;
    let nextUnit = unitInfoLst[idx + 1];
    if (nextUnit) {
        this.getPathUnitDesc(nextUnit, outParam, idx + 1, unitInfoLst);
    }
}

export { SvgPath2LGXPathSvc }